<template>
    <!-- 过渡动画 -->
    <transition name="fade">
        <div id='overlay' class="fade-enter-active" @click='close'>
            <img :src='imgsource.imgUrl' alt='' />
        </div>
    </transition>
</template>

<script>
    export default {
        props: {
            imgsource: Object,
            close: Function
        },
        mounted: function() {
            var overlay = document.getElementById('overlay')
            overlay.setAttribute('style', 'height:' + window.innerHeight + 'px; ' + 'width:' + window.innerWidth + 'px')
        }
    }
</script>

<style scoped>
img {
  width: 100%;
}

#overlay {
  position: fixed;
  width: 100vw;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  top: 0;
  left: 0;
  z-index: 1000;
}

#overlay img {
  width: auto;
}

#overlay span {
  color: white;
  margin-top: 1rem;
}

.fade-enter-active, .fade-leave-active {
  transition: opacity .5s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}

@media only screen and (max-width: 500px) {
  .image {
    width: 80%;
  }
  #overlay img {
    height: auto;
    width: 90%;
  }
}

@media only screen and (max-width: 800px) and (min-width: 500px) {
  .image {
    width: 30%;
  }
  #overlay img {
    height: auto;
    width: 90%;
  }
}
</style>
